import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAuthStore = defineStore('auth', () => {
  const isAuthenticated = ref(false)
  const user = ref(null)

  const login = (username: string, password: string) => {
    if ((username === 'admin' || username === '初九') && password === 'admin') {
      isAuthenticated.value = true
      user.value = { username: '初九' }
      return true
    }
    return false
  }

  const logout = () => {
    isAuthenticated.value = false
    user.value = null
  }

  return {
    isAuthenticated,
    user,
    login,
    logout
  }
})